package com.stu.day10.SOLID;

/**
 * 开闭原则:对拓展开放,对修改关闭
 * @author zy
 * @date 2025/2/1 18:07
 */

// 定义员工接口
public interface Employee {
    double calculateSalary();
}

// 普通员工实现
class RegularEmployee implements Employee {
    private double baseSalary;

    public RegularEmployee(double baseSalary) {
        this.baseSalary = baseSalary;
    }

    @Override
    public double calculateSalary() {
        return baseSalary;
    }
}

// 销售员工实现
class SalesEmployee implements Employee {
    private double baseSalary;
    private double salesRevenue;

    public SalesEmployee(double baseSalary, double salesRevenue) {
        this.baseSalary = baseSalary;
        this.salesRevenue = salesRevenue;
    }

    @Override
    public double calculateSalary() {
        return baseSalary + salesRevenue * 0.1;
    }
}
/*
  如果要添加一个新的员工类型（例如Manager），
  只需要创建一个新的类Manager实现Employee接口，并实现calculateSalary方法。
  我们不需要修改现有的SalaryCalculator类。
 */
// 薪水计算器
class SalaryCalculator {
    public double calculate(Employee employee) {
        return employee.calculateSalary();
    }
}

